package wodegua.d23_test.timer;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.TimerTask;

public class TimeTask extends TimerTask {
    private static LocalDateTime startTime;
    @Override
    public void run() {
        String s= "2024-03-22 22:00:00";
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        startTime = LocalDateTime.parse(s,formatter);

        LocalDateTime now = LocalDateTime.now();
        Duration duration = Duration.between(now,startTime);

        long days = duration.toDays();
        duration = duration.minusDays(days);

        long hours = duration.toHours();
        duration = duration.minusHours(hours); // 从原始时间中减去小时数

        long minutes = duration.toMinutes();
//        duration = duration.minusMinutes(minutes); // 从原始时间中减去分钟数

        long seconds = duration.getSeconds();
//
        System.out.println(days + " 天 "
                + hours + " 时 "
                + minutes + " 分 "
                + seconds + "秒");
//        long days = duration.toDays(); // 相差的天数
//        duration = duration.minusDays(days); // 从原始时间中减去天数
//
//        long hours = duration.toHours(); // 相差的小时数
//        duration = duration.minusHours(hours); // 从原始时间中减去小时数
//
//        long minutes = duration.toMinutes(); // 相差的分钟数
//        duration = duration.minusMinutes(minutes); // 从原始时间中减去分钟数
//
//        long seconds = duration.getSeconds(); // 相差的秒数
//
//        System.out.println("天数: " + days);
//        System.out.println("小时数: " + hours);
//        System.out.println("分钟数: " + minutes);
//        System.out.println("秒数: " + seconds);
    }
}
